package com.example.springboottpl.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import jakarta.validation.groups.Default;

import com.example.springboottpl.annotation.OperateLog;
import com.example.springboottpl.service.MenuService;
import com.example.springboottpl.util.Result;
import com.example.springboottpl.util.ResultPage;
import com.example.springboottpl.vo.common.DeleteReqVo;
import com.example.springboottpl.vo.common.QueryDetailReqVo;
import com.example.springboottpl.vo.common.UpdateStatusReq;
import com.example.springboottpl.vo.common.valid.Insert;
import com.example.springboottpl.vo.common.valid.Update;
import com.example.springboottpl.vo.req.MenuReqVo;
import com.example.springboottpl.vo.req.QueryMenuReqVo;
import com.example.springboottpl.vo.resp.MenuRespVo;
import com.example.springboottpl.vo.resp.MenuSimpleRespVo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

/**
 * 描述：菜单信息
 * 作者：刘飞华
 * 日期：2025/01/15 15:09:35
 */
@Tag(name = "3.菜单信息")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 添加菜单信息
     *
     * @param menu 请求参数
     * @return Result<Integer>
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "1.1 添加菜单信息")
    @PostMapping("/addMenu")
    @OperateLog(description = "【菜单信息】添加菜单信息")
    public Result<Integer> addMenu(@RequestBody @Validated({Insert.class, Default.class}) MenuReqVo menu) {
        return menuService.addMenu(menu);
    }

    /**
     * 删除菜单信息
     *
     * @param menu 请求参数
     * @return Result<Integer>
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "1.2 删除菜单信息")
    @PostMapping("/deleteMenu")
    @OperateLog(description = "【菜单信息】删除菜单信息")
    public Result<Integer> deleteMenu(@RequestBody @Valid DeleteReqVo menu) {
        return menuService.deleteMenu(menu);
    }

    /**
     * 更新菜单信息
     *
     * @param menu 请求参数
     * @return Result<Integer>
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "1.3 更新菜单信息")
    @PostMapping("/updateMenu")
    @OperateLog(description = "【菜单信息】更新菜单信息")
    public Result<Integer> updateMenu(@RequestBody @Validated({Update.class, Default.class}) MenuReqVo menu) {
        return menuService.updateMenu(menu);
    }

    /**
     * 更新菜单信息状态
     *
     * @param menu 请求参数
     * @return Result<Integer>
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "1.4 更新菜单信息状态")
    @PostMapping("/updateMenuStatus")
    @OperateLog(description = "【菜单信息】更新菜单信息状态")
    public Result<Integer> updateMenuStatus(@RequestBody @Valid UpdateStatusReq menu) {
        return menuService.updateMenuStatus(menu);
    }

    /**
     * 查询菜单信息详情
     *
     * @param menu 请求参数
     * @return MenuResp
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 5)
    @Operation(summary = "1.5 查询菜单信息详情")
    @PostMapping("/queryMenuDetail")
    @OperateLog(description = "【菜单信息】查询菜单信息详情")
    public Result<MenuRespVo> queryMenuDetail(@RequestBody @Valid QueryDetailReqVo menu) {
        return menuService.queryMenuDetail(menu);
    }

    /**
     * 查询菜单信息列表
     *
     * @param menu 请求参数
     * @return List
     * @author 刘飞华
     * @date: 2025/01/15 15:09:35
     */
    @ApiOperationSupport(order = 6)
    @Operation(summary = "1.6 查询菜单信息列表")
    @PostMapping("/queryMenuList")
    @OperateLog(description = "【菜单信息】查询菜单信息列表")
    public Result<List<MenuRespVo>> queryMenuList(@RequestBody @Valid QueryMenuReqVo menu) {
        return menuService.queryMenuList(menu);
    }

    /**
     * 查询菜单信息(排除按钮)
     *
     * @return List
     * @author 刘飞华
     * @date: 2025/1/20 9:10
     */
    @ApiOperationSupport(order = 7)
    @Operation(summary = "1.7 查询菜单信息(排除按钮)")
    @PostMapping("/queryMenuListSimple")
    @OperateLog(description = "【菜单信息】查询菜单信息(排除按钮)")
    public Result<List<MenuSimpleRespVo>> queryMenuListSimple() {
        return menuService.queryMenuListSimple();
    }


    /**
     * 查询菜单资源
     *
     * @param menu 请求参数
     * @return res
     * @author 刘飞华
     * @date: 2025/10/27 9:42
     */
    @ApiOperationSupport(order = 8)
    @Operation(summary = "1.8 查询菜单资源")
    @PostMapping("/queryMenuResourceList")
    @OperateLog(description = "【菜单信息】查询菜单资源")
    public Result<ResultPage<MenuRespVo>> queryMenuResourceList(@RequestBody @Valid QueryMenuReqVo menu) {
        return menuService.queryMenuResourceList(menu);
    }
}
